<template>
  <div class="tipCard">

    <div v-if="examType == 6" class="symbolView">

      <div class="statusView" style="background-color: #00CC99;border: 1px solid #00CC99">

      </div>
      <p>
        答对
      </p>

      <div class="statusView" style="margin-left: 12px; background-color: #FF3300;border: 1px solid #FF3300">

      </div>
      <p>
        答错
      </p>


    </div>

    <div v-else class="symbolView">

      <div class="statusView" style="background-color: #1286F7; border: #1286F7 solid 1px">

      </div>
      <p>
        已作答
      </p>

      <div class="statusView" style="margin-left: 12px; background-color: white; border: #9B9B9B solid 1px">

      </div>
      <p>
        未作答
      </p>

    </div>

    <div style="height: 240px">


      <div style="height: 120px">
        <div class="chooseView">
          <div v-for="(el, idx) in questionList" :class="'itemView ' + questionItemClass(idx)" @click="itemClick(idx)">
            {{idx + 1}}
          </div>
        </div>
      </div>

    </div>

  </div>
</template>

<script>

  // import Vue from 'vue'
  import {Dialog} from 'vant'

  Vue.use(Dialog)

  export default {
    name: 'TipCardPc-m',
    model: {
      prop: 'selectedIndex',
      event: 'changeSelectedIndex'
    },
    props: ['questionList', 'selectedIndex', 'answerData', 'examType'],
    computed: {

    },
    methods: {
      questionItemClass(idx) {
        //题目标卡的颜色class

        let question = this.questionList[idx]
        let answer = this.answerData[question.id] || {}

        let itemClass

        if (question.isMix) {
          //综合题
          let items = question.questions
          if (this.examType == 6) {
            //题目分析
            let wrong = false
            items.forEach((item) => {
              //如果有题目没有做，初始化一个空值
              let myAnswer = answer[item.id] || {'answer': []}
              //判断答案是否一致，综合题有一道题不对就是错的
              if (JSON.parse(item.result).join('') != myAnswer.answer.join('')) {
                wrong = true
              }
            })
            itemClass = wrong == true ? 'itemView_wrong' : 'itemView_right'

          } else {
            //普通模式
            if (answer && Object.keys(answer).length == items.length) {
              itemClass = 'itemView_complete'
            } else {
              itemClass = 'itemView_todo'
            }
          }

        } else {
          //单选多选题

          if (this.examType == 6) {
            //题目分析
            let myAnswer = answer.answer || []
            itemClass = JSON.parse(question.result).join('') == myAnswer.join('') ? 'itemView_right' : 'itemView_wrong'
          } else {
            //普通模式
            if (answer.answer) {
              itemClass = 'itemView_complete'
            } else {
              itemClass = 'itemView_todo'
            }
          }

        }
        if (idx == this.selectedIndex) {

          return itemClass + ' itemView_selected'
        } else {
          return itemClass
        }

      },
      //题目点击
      itemClick(idx) {
        this.$emit('changeSelectedIndex', idx)
        this.$emit('sendCloseTipCard')
        window.scrollTo(0,0);
      },


    }
  }
</script>

<style scoped>
  .tipCard {
    box-sizing: border-box;
    padding: 16px;
    background-color: white;
  }
  .chooseView {
    margin-top: 16px;
    max-height: 200px;
    display: flex;
    flex-wrap: wrap;
    overflow-y: scroll;
    overflow-x: hidden;
  }

  .itemView_complete {
    background-color: #1286F7;
    border: #1286F7 solid 1px;
    color: white;
  }
  .itemView_todo {
    background-color: white;
    border: #9B9B9B solid 1px;
    color: #333333;
  }
  .itemView_right {
    background-color: #00CC99;
    border: #00CC99 solid 1px;
    color: white;
  }
  .itemView_wrong {
    background-color: #FF3300;
    border: #FF3300 solid 1px;
    color: white;
  }
  .itemView_selected {
    border: #1286F7 solid 1px;
  }

  .itemView {
    width: 32px;
    height: 32px;
    margin-right: 8px;
    margin-bottom: 8px;
    line-height: 32px;
    text-align: center;
    border-radius: 50%;
  }

  .symbolView {
    display: flex;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 1px solid #E7E7E7;
  }

  .symbolView p {
    font-size: 12px;
    margin-left: 2px;
    color: #333333;
  }

  .statusView {
    width: 16px;
    height: 16px;
    border-radius: 50%;
  }

</style>

